<%@page import="dao.LoginDAO"%>
<%@page import="entity.Visitor"%>
<%@ taglib prefix="s" uri="/struts-tags" %>

<%
    Visitor visitor = null;
    String visitorName = "^_^";
    String exeption = "Exception: No";
    int n = 0;
    try{    	
    	visitor = (Visitor)session.getAttribute("curSession");
        if(visitor != null){
        	System.out.println(" Login page say of curSession:  " + visitor.getUserName());
    	    response.sendRedirect("index.jsp");
        }else{
            //response.sendRedirect("homepage.jsp");
            Cookie [] cookies = request.getCookies();
            n = cookies.length;
            if(n>0){
                for(int i=0; i<n; i++){
    	        	if(cookies[i].getName().equals("c_u")){
    	        		visitorName = cookies[i].getValue();
    	        		visitor = LoginDAO.checkReVisistor(visitorName);
    	        		session.setAttribute("curSession", visitor);
    	        		
                	}    	        	
    	        }    	    
            }
            if(visitor != null){
        	    response.sendRedirect("index.jsp");
            }            
        } 
    
    }catch(Exception ex){
        System.out.println(" login page says: " + ex.getMessage());
    }
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title> Login Page</title>
	<link href="css/java_tech_css.css" rel="stylesheet" type="text/css"/>
</head>
<body>
	<div id="container">	
		<div class="login">
				<h3>Login</h3>
		</div>
		<div class="content">
			<div class="form">
			    <s:form action="login" method="post" id="input_form" name="formLogin" validate="true">
					<div class="row">
						<div class="col1">
							<p>Username :</p>
						</div>
						<div class="col2">
							<input type="text" name="userName" id="username"/>
						</div>
					</div>
					<div class="row">
						<div class="col1">
							<p>Password :</p>
						</div>
						<div class="col2">
							<input type="password" name="password" id="password"/>
						</div>
					</div>
					<div class="row">
						<input style="margin-left: 170px;" type="checkbox" name="checkremember"> Remember me!
					</div>
					<div class="btn-login">
						<input type="submit" value="Login">
						<input type="reset" value="Reset"> 
						<a href="rsPass-form"> forgot password? </a> 
					</div>									
					
				</s:form>
<!--  Message nay nen cho vao giua khung -->
				<span class="error" ><s:actionerror/> </span> 		
			</div>
		</div>				
	</div>
</body>
</html>